package oneway01;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
/**
* @Description: 生产者发送消息
* @Author: Mr.She
* @Version: 1.0
* @Date:  2022/8/16 15:09
*/
public class Producer {

    public static void main(String[] args) throws Exception {
        // 1.创建生产者对象
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("producer_hello_group");
        // 2.设置NameServer地址,均衡调用对象
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        // 3.启动producer实例
        defaultMQProducer.start();
        // 4.创建消息
        Message message = new Message("hello_topic", "hello_tags", "我使用的是单向发送".getBytes(StandardCharsets.UTF_8));
        // 5.发送消息
        SendResult sendOneway = defaultMQProducer.send(message);
        // 6.关闭producer实例
        System.out.println(sendOneway);
        defaultMQProducer.shutdown();
    }

}
